using System;
using System.Data;
using AIFSCMS.Infrastructure.ProxyModels;
using AIFSContentManagementSystem.Articles;
using AIFSContentManagementSystem;
using AIFSDataAccessLayer.Utilities;

namespace AIFSCMS.Infrastructure.EntityMappers
{
    public class ArticleMapper : EntityMapper<ArticleProxy>
    {
        protected override void Map(DataRow drEntity, ArticleProxy dto)
        {            
            dto.Active = DataTableUtil.ToBoolType(drEntity, "ACTIVE_FLAG");
            dto.ArticleId = DataTableUtil.ToIntType(drEntity, "ARTICLE_ID");

            string strArticleType = DataTableUtil.ToStringType(drEntity, "ARTICLE_TYPE_CODE");

            try
            {
                dto.ArticleType = (ArticleType)Enum.Parse(typeof(ArticleType), strArticleType);
            }
            catch (Exception ex)
            {
                throw new AIFSCMSInfrastructureException(string.Format("Article Type {0} specified is not supported.", strArticleType), ex);
            }

            dto.Program = DataTableUtil.ToStringType(drEntity, "PROGRAM");
            dto.EffectiveFrom = DataTableUtil.ToDateTimeType(drEntity, "EFFECTIVE_FROM");
            dto.EffectiveThru = DataTableUtil.ToDateTimeType(drEntity, "EFFECTIVE_THRU");
        }
    }
}
